//
//  DDBossEditInfoViewController.m
//  DingDongZP
//
//  Created by weily on 16/4/21.
//  Copyright © 2016年 iyhjiang.com. All rights reserved.
//

#import "DDBossEditInfoViewController.h"
#import "DDEditInfoCell.h"
#import "DDBossInfoService.h"
#import "DDBossInfo.h"
#import "DDInfoEditViewController.h"
#import "DDBossTagViewController.h"
#import "DDBossSetPositionViewController.h"
#import "DDIndustrySelectViewController.h"
#import "DDCompanySize.h"
#import "DDCompanyFinance.h"
#import "DDTextFieldEditViewController.h"
#import "DDTextViewEditViewController.h"
#import "DDCompanyImageViewController.h"
#import "DDDefaultsAvatarView.h"
#import "DDAvatarPickerView.h"
#import "CCImageGetter.h"
#import "DDSegementTabbarView.h"
#import "DDCompanyHomeService.h"

/// boss编辑用户信息

@interface DDBossEditInfoViewController ()
<
UITableViewDataSource,
UITableViewDelegate,
UIImagePickerControllerDelegate,
UINavigationControllerDelegate
>

@property (nonnull, strong) NSArray *sectionTitleArray;
@property (nonnull, strong) NSArray *titleArray;
@property (nonatomic, strong) DDBossInfoService *service;
@property (nonatomic, strong) DDBossInfo *userInfo;
@property (nonatomic, strong) NSArray *sizeArray;
@property (nonatomic, strong) NSArray *financeArray;
@property (strong, nonatomic) DDSegementTabbarView *segmentView;
// 筛选类型
@property (strong, nonatomic) NSString *filterType;
// 筛选条件ID
@property (strong, nonatomic) NSString *filterId;
@property (nonatomic, strong) DDCompanyInfo *companyInfo;

@property (nonatomic, assign) BOOL haveLogo;
@property (nonatomic, assign) BOOL haveName;
@property (nonatomic, assign) BOOL haveWeiXin;
@property (nonatomic, assign) BOOL havePosition;
@property (nonatomic, assign) BOOL haveLight;
@property (nonatomic, assign) BOOL haveCompanyIntro;
@property (nonatomic, assign) BOOL haveCompanyShotrName;
@property (nonatomic, assign) BOOL haveCompanyStyle;
@property (nonatomic, assign) BOOL haveCompanySize;
@property (nonatomic, assign) BOOL haveCompanyShow;
@property (nonatomic, assign) BOOL haveCompanyLongName;
@property (nonatomic, assign) BOOL haveCompanyWebsize;
@property (nonatomic, assign) BOOL haveCompanyAddress;


@end

@implementation DDBossEditInfoViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    self.view.backgroundColor = COLOR_BACKGROUND_GRAY;
    self.title = @"编辑信息";
    
    UIBarButtonItem *rightButton = [[UIBarButtonItem alloc] initWithTitle:@"保存" style:UIBarButtonItemStylePlain target:self action:@selector(saveAction)];
    self.navigationItem.rightBarButtonItem = rightButton;
    
    self.sectionTitleArray = @[@"个人信息",@"团队信息",@"公司信息"];
    
    self.titleArray = @[@[@"头像", @"姓名", @"微信号"],
                        @[@"我的身份", @"团队亮点", @"团队介绍"],
                        @[@"公司简称", @"公司行业", @"公司规模", @"办公环境",@"公司全称", @"公司官网", @"公司地址"]];
   
    self.haveLogo = YES;
    self.haveName = YES;
    self.haveWeiXin = YES;
    self.havePosition = YES;
    self.haveLight = YES;
    self.haveCompanyIntro = YES;
    self.haveCompanyShotrName = YES;
    self.haveCompanyStyle = YES;
    self.haveCompanySize = YES;
    self.haveCompanyShow = YES;
    self.haveCompanyLongName = YES;
    self.haveCompanyWebsize = YES;
    self.haveCompanyAddress = YES;

    [self loadUserInfo];
    [self loadCompanySize];
    [self loadFinance];
}

- (void) viewWillAppear:(BOOL)animated {
    
    [super viewWillAppear:animated];
    [self.rdv_tabBarController setTabBarHidden:true animated:true];
    [self loadInfoDataCampany];
}
#pragma mark - setter/getter
- (DDBossInfoService *)service
{
    if (!_service) {
        _service = [[DDBossInfoService alloc] init];
    }
    return _service;
}

#pragma mark - data
- (void)loadUserInfo
{
    WEAKSELF;
    [self.service queryBossInfoWithSuccessBlock:^(id responseObject) {
        if ([weakSelf isValidateResponseData:responseObject]) {
            DDBossInfo *model = [DDBossInfo yy_modelWithJSON:responseObject[@"data"]];
//            NSLog(@"model____%@",model);
            weakSelf.userInfo = model;
            dispatch_main_async_safe(^{

                [self checkData];

                [weakSelf.tableView reloadData];
            });
        } else {
//            [weakSelf responseUnValidate:responseObject];
        }
    } failBlock:^(id responseObject, NSError *error) {
        [weakSelf requestFaild];
    }];
}

- (void)loadCompanySize {
    WEAKSELF
    [self.service queryCompanySize:^(NSArray *companySizes) {
        weakSelf.sizeArray = companySizes;
        [weakSelf.tableView reloadData];
    }];
}

- (void)loadFinance {
    WEAKSELF
    [self.service queryCompanyFinance:^(NSArray *companyFinance) {
        weakSelf.financeArray = companyFinance;
    }];
}

- (void)loadInfoDataCampany {
    
    [[DDCompanyHomeService sharedService] queryCompanyInfo:^(id responseObject, NSError *error) {
        
        if ([responseObject isKindOfClass:[DDCompanyInfo class]]) {
            
            self.companyInfo = responseObject;
            
            WEAKSELF
            dispatch_main_async_safe(^{
                
                [self checkData];
                
                [weakSelf.tableView reloadData];
            });
        }
    }];
}



#pragma mark - delegates
#pragma mark -- tableView

- (CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section
{

    return 50;
}

- (nullable UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section
{
    UIView *sectionView = [[UIView alloc]init];
    UILabel *sectionLabel = [[UILabel alloc]initWithFrame:CGRectMake(15, 0, 150, 50)];
    sectionLabel.textColor = COLOR_FONT_BLACK;
    sectionLabel.font = [UIFont systemFontOfSize:16];
    sectionLabel.text = self.sectionTitleArray[section];
    [sectionView addSubview:sectionLabel];
    return sectionView;
}

- (CGFloat )tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
{
    if (indexPath.row == 0 && indexPath.section == 0) {
        return 74.f;
    }
    
    return 47.f;
}

- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
{
    return self.titleArray.count;
}

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
    if (section < self.titleArray.count) {
        NSArray *titles = self.titleArray[section];
        return titles.count;
    }
    return 0;
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    DDEditInfoCell *cell = nil;

    tableView.backgroundColor = COLOR_BACKGROUND;
    if (indexPath.row == 0 && indexPath.section == 0)
    {
        cell = [tableView dequeueReusableCellWithIdentifier:@"head"];
        if (!cell) {
            cell = (DDEditInfoCell *)[[[NSBundle mainBundle] loadNibNamed:@"DDEditInfoHeaderCell" owner:self options:nil] lastObject];
        }
        cell.headerImageView.image = [UIImage imageNamed:@"common_avatar"];
        
        cell.titleLabel.textColor = self.haveLogo == YES ? [UIColor colorWithWhite:0.333 alpha:1.000]:COLOR_FONT_RED;
        
        if (self.userInfo) {
            NSString *url = [DDAPIGenerate imageURLWithPath:self.userInfo.logo];
            [cell.headerImageView sd_setImageWithURL:[NSURL URLWithString:url] placeholderImage:[UIImage imageNamed:@"common_avatar"] options:SDWebImageRefreshCached];
        }
    }
    else
    {
        cell = [tableView dequeueReusableCellWithIdentifier:@"cell"];
        if (!cell) {
            cell = (DDEditInfoCell *)[[[NSBundle mainBundle] loadNibNamed:@"DDEditInfoCell" owner:self options:nil] lastObject];
        }
        
        //  设置显示内容
        [self configureCell:cell indexPath:indexPath];
    }
    if (indexPath.section < self.titleArray.count && indexPath.row < [self.titleArray[indexPath.section] count]) {
        cell.titleLabel.text = self.titleArray[indexPath.section][indexPath.row];
    }
    cell.backgroundColor = [UIColor whiteColor];
    return cell;
}

//  设置显示内容
- (void)configureCell:(DDEditInfoCell *)cell indexPath:(NSIndexPath *)indexPath
{
    
    if (indexPath.section == 0)
    {
        switch (indexPath.row) {
            case 1:
                cell.infoLabel.text = self.haveName == YES ? self.userInfo.name : @"必填";
                cell.titleLabel.textColor = self.haveName == YES ? [UIColor colorWithWhite:0.333 alpha:1.000]:COLOR_FONT_RED;
                cell.infoLabel.textColor = self.haveName == YES ? [UIColor colorWithWhite:0.333 alpha:1.000]:COLOR_FONT_RED;
                break;
            case 2:
                cell.infoLabel.text = self.haveWeiXin == YES ? self.userInfo.weixin : @"必填";
                cell.titleLabel.textColor = self.haveWeiXin == YES ? [UIColor colorWithWhite:0.333 alpha:1.000]:COLOR_FONT_RED;
                cell.infoLabel.textColor = self.haveWeiXin == YES ? [UIColor colorWithWhite:0.333 alpha:1.000]:COLOR_FONT_RED;
                break;
            case 3:
                cell.infoLabel.text = self.userInfo.email;
                break;
            default:
                break;
        }
    }
    else if (indexPath.section == 1) {
        
        switch (indexPath.row) {
                
            case 0: {
                
                cell.infoLabel.text = self.havePosition == NO ? @"必填" : self.userInfo.positioncustomized ? self.userInfo.positioncustomized : self.userInfo.positionname;
                cell.titleLabel.textColor = self.havePosition == YES ? [UIColor colorWithWhite:0.333 alpha:1.000]:COLOR_FONT_RED;
                cell.infoLabel.textColor = self.havePosition == YES ? [UIColor colorWithWhite:0.333 alpha:1.000]:COLOR_FONT_RED;
                break;
            }
                
            case 1:
                
                cell.infoLabel.text = self.haveLight == YES ? [NSString stringWithFormat:@"%ld个标签", self.userInfo.teamhighlightscount.integerValue] : @"必填";
                cell.titleLabel.textColor = self.haveLight == YES ? [UIColor colorWithWhite:0.333 alpha:1.000]:COLOR_FONT_RED;
                cell.infoLabel.textColor = self.haveLight == YES ? [UIColor colorWithWhite:0.333 alpha:1.000]:COLOR_FONT_RED;
                break;
                
            case 2:
                
                cell.infoLabel.text = self.haveCompanyIntro == YES ? self.userInfo.teamintro : @"必填";
                cell.titleLabel.textColor = self.haveCompanyIntro == YES ? [UIColor colorWithWhite:0.333 alpha:1.000]:COLOR_FONT_RED;
                cell.infoLabel.textColor = self.haveCompanyIntro == YES ? [UIColor colorWithWhite:0.333 alpha:1.000]:COLOR_FONT_RED;
                break;
                
            default:
                break;
        }
    }
    else if (indexPath.section == 2)
    {
        switch (indexPath.row) {
            case 0:
                cell.infoLabel.text = self.haveCompanyShotrName == YES ? self.userInfo.companyshortname : @"必填";
                cell.titleLabel.textColor = self.haveCompanyShotrName == YES ? [UIColor colorWithWhite:0.333 alpha:1.000]:COLOR_FONT_RED;
                cell.infoLabel.textColor = self.haveCompanyShotrName == YES ? [UIColor colorWithWhite:0.333 alpha:1.000]:COLOR_FONT_RED;
                break;
            case 1:
                cell.infoLabel.text = self.haveCompanyStyle == YES ? self.userInfo.industry : @"必填";
                cell.titleLabel.textColor = self.haveCompanyStyle == YES ? [UIColor colorWithWhite:0.333 alpha:1.000]:COLOR_FONT_RED;
                cell.infoLabel.textColor = self.haveCompanyStyle == YES ? [UIColor colorWithWhite:0.333 alpha:1.000]:COLOR_FONT_RED;
                break;
            case 2:
                cell.infoLabel.text = self.haveCompanySize == YES ? self.userInfo.companysize : @"必填";
                cell.titleLabel.textColor = self.haveCompanySize == YES ? [UIColor colorWithWhite:0.333 alpha:1.000]:COLOR_FONT_RED;
                cell.infoLabel.textColor = self.haveCompanySize == YES ? [UIColor colorWithWhite:0.333 alpha:1.000]:COLOR_FONT_RED;
                break;
            case 3:
                cell.infoLabel.text = self.haveCompanyShow == YES ? @"" : @"必填";
                cell.titleLabel.textColor = self.haveCompanyShow == YES ? [UIColor colorWithWhite:0.333 alpha:1.000]:COLOR_FONT_RED;
                cell.infoLabel.textColor = self.haveCompanyShow == YES ? [UIColor colorWithWhite:0.333 alpha:1.000]:COLOR_FONT_RED;
                break;
            case 4:
                cell.infoLabel.text = self.haveCompanyLongName == YES ? self.userInfo.companyfullname : @"必填";
                cell.titleLabel.textColor = self.haveCompanyLongName == YES ? [UIColor colorWithWhite:0.333 alpha:1.000]:COLOR_FONT_RED;
                cell.infoLabel.textColor = self.haveCompanyLongName == YES ? [UIColor colorWithWhite:0.333 alpha:1.000]:COLOR_FONT_RED;
                break;
            case 5:
                cell.infoLabel.text = self.haveCompanyWebsize == YES ? self.userInfo.companywebsite : @"必填";
                cell.titleLabel.textColor = self.haveCompanyWebsize == YES ? [UIColor colorWithWhite:0.333 alpha:1.000]:COLOR_FONT_RED;
                cell.infoLabel.textColor = self.haveCompanyWebsize == YES ? [UIColor colorWithWhite:0.333 alpha:1.000]:COLOR_FONT_RED;
                break;
            case 6:
                cell.infoLabel.text = self.haveCompanyAddress == YES ? self.userInfo.companyaddress : @"必填";
                cell.titleLabel.textColor = self.haveCompanyAddress == YES ? [UIColor colorWithWhite:0.333 alpha:1.000]:COLOR_FONT_RED;
                cell.infoLabel.textColor = self.haveCompanyAddress == YES ? [UIColor colorWithWhite:0.333 alpha:1.000]:COLOR_FONT_RED;
                break;
            default:
                break;
        }
    }
}

- (CGFloat)tableView:(UITableView *)tableView heightForFooterInSection:(NSInteger)section
{
    return 1;
}

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
    [tableView deselectRowAtIndexPath:indexPath animated:YES];
    NSString *title =self.titleArray[indexPath.section][indexPath.row];
    if (indexPath.section == 0) {
        
        switch (indexPath.row) {
            case 0:
                [self editAvatar];
                break;
            case 1:
                [self editInfoWithTitle:title
                                  value:self.userInfo.name
                               infoType:DDBossInfoTypeName];
                break;
            case 2:
                [self editInfoWithTitle:title
                                  value:self.userInfo.weixin
                               infoType:DDBossInfoTypeWx];

                break;
            case 3:
                [self editInfoWithTitle:title
                                  value:self.userInfo.email
                               infoType:DDBossInfoTypeEmail];
                break;
            default:
                break;
        }
    } else if (indexPath.section == 1) {
        
        switch (indexPath.row) {
            case 0:
                [self editPosition];
                break;
            case 1:
                [self editLights];
                break;
            case 2:
                [self editIntroduce];
            default:
                break;
        }
    } else if (indexPath.section == 2) {
        
        switch (indexPath.row) {
            case 0:
                [self editInfoWithTitle:title
                                  value:self.userInfo.companyshortname
                               infoType:DDBossInfoTypeShortName];
                break;
            case 1:
                [self editIndustry];
                break;
            case 2:
                [self editCompanySize];
                break;
            case 3:
            {
                
                DDCompanyImageViewController *vc = [[DDCompanyImageViewController alloc] init];
                vc.companyInfo = self.companyInfo;
                vc.hidesBottomBarWhenPushed = YES;
                [self.navigationController pushViewController:vc animated:YES];
                
            }
                break;
            case 4:
                [self editInfoWithTitle:title
                                  value:self.userInfo.companyfullname
                               infoType:DDBossInfoTypeFullname];
                break;
            case 5:
                [self editInfoWithTitle:title
                                  value:self.userInfo.companywebsite
                               infoType:DDBossInfoTypeWebsite];
                break;
            case 6:
                [self editInfoWithTitle:title
                                  value:self.userInfo.companyaddress
                               infoType:DDBossInfoTypeAddress];
                break;
                
            default:
                break;
        }
    }
}

#pragma mark - functions...

- (void)editInfoWithTitle:(NSString *)title value:(NSString *)value infoType:(DDBossInfoType)type
{
    WEAKSELF
    DDTextFieldEditViewController *vc = [[DDTextFieldEditViewController alloc] init];
    vc.title = title;
    vc.value = value;
    
    //  公司官网只能输入字母
    if (type == DDBossInfoTypeWebsite) {
        vc.textField.keyboardType = UIKeyboardTypeURL;
        vc.textFilter = ^(NSString *text) {
            for (int i = 0; i < text.length; i++) {
                unichar ch = [text characterAtIndex:i];
                if ((int)ch > 127) {
                    return NO;
                }
            }
            return YES;
        };
    }
    //  都是50个，只有名称是4个字
    vc.maxCharacterNumber = 50;
    if (type == DDBossInfoTypeName) {
        vc.maxCharacterNumber = 14;
    }
    
    vc.block = ^(NSString *value) {
//        [weakSelf showLoadingWithText:@"加载中..."];
        [weakSelf.service eidtInfoType:type value:value callback:^(BOOL succ, NSString *err) {
            if (succ) {
                [weakSelf hideLoading];
                [weakSelf loadUserInfo];
                [[NSNotificationCenter defaultCenter] postNotificationName:NOTI_BOSS_EDIT_PERSIONINFO object:nil];
                
                if (type == DDBossInfoTypeWx) {
                    [DDLoginUserManager setWeixin:value];
                }
                
                if (type == DDBossInfoTypeName) {
                    
                    [DDLoginUserManager setAccountNamefirst:value];
                }
            }
            else {
                [weakSelf showErrorWithText:err];
            }
        }];
    };
    [self.navigationController pushViewController:vc animated:YES];
}

- (void)editLights
{
    LDBossSkilTags *tagsvc = [[LDBossSkilTags alloc] init];
    tagsvc.type = LDTagsViewTypeTeamHeigLight;
    tagsvc.title = @"设置团队亮点";
    
    NSMutableArray *titleArr = [NSMutableArray array];
    NSMutableArray *titleArrID = [NSMutableArray array];
    
    for (NSDictionary *item in _userInfo.teamhighlights) {
        
        [titleArr addObject:item[@"tagid"]];
        [titleArrID addObject:item[@"tagtext"]];
    }
    
    tagsvc.preSelHightIDParams = titleArr;
    WEAKSELF
    [tagsvc getParmasFromSelTags:^(NSDictionary<NSString *,id> * _Nonnull dict) {
       
        if (dict.count == 0) {
            
            return;
        }
        
        [self.service eidtInfoType:DDBossInfoTypeLight value:[dict jsonStringEncoded] callback:^(BOOL succ, NSString *err) {
            
            if (succ) {
                [weakSelf loadUserInfo];
            }
            else {
                [[LDShowHUB shareInstance] showToastNoti:err];
            }
            
        }];
    }];
    [self.navigationController pushViewController:tagsvc animated:YES];
}

- (void)editPosition
{
    DDBossSetPositionViewController *vc = [[DDBossSetPositionViewController alloc] init];
    vc.positionName = self.userInfo.positionname;
    vc.positionCustomName = self.userInfo.positioncustomized;
    WEAKSELF
    vc.didSelectPosition = ^(NSString *pid, NSString *pname) {
        
        [weakSelf showLoading];
        
        /**
         *  当不是自定义boss身份的时候，也可以通过获取点击标签，获得当前身份，将所有的身份都通过下面的自定义身份的接口传给服务器。以解决自定义身份以及非自定义身份网络请求冲突引起的Bug
         *
         */
//        [weakSelf.service eidtInfoType:DDBossInfoTypePosition value:pid callback:^(BOOL succ, NSString *err) {
//            if (succ) {
//                [weakSelf hideLoading];
//                [weakSelf loadUserInfo];
//            }
//            else {
//                [weakSelf showErrorWithText:err];
//            }
//        }];
        [weakSelf.service eidtInfoType:DDBossInfoTypePositionCustom value:pname callback:^(BOOL succ, NSString *err) {
            if (succ) {
                [weakSelf hideLoading];
                [weakSelf loadUserInfo];
            }
            else {
                [weakSelf showErrorWithText:err];
            }
        }];
        
        [[NSNotificationCenter defaultCenter] postNotificationName:NOTI_BOSS_EDIT_PERSIONINFO object:nil];
    };
    [self.navigationController pushViewController:vc animated:YES];
}

- (void)editIndustry {
    DDIndustrySelectViewController *vc = [[DDIndustrySelectViewController alloc] init];
    vc.selectIndustryName = self.userInfo.industry;
    WEAKSELF
    vc.didSelectIndustry = ^(DDIndustry *industry) {
        [weakSelf showLoading];
        [weakSelf.service eidtInfoType:DDBossInfoTypeIndustry value:industry.industry_id callback:^(BOOL succ, NSString *err) {
            if (succ) {
                [weakSelf hideLoading];
                [weakSelf loadUserInfo];
            } else {
                [weakSelf showErrorWithText:err];
            }
        }];
    };
    [self.navigationController pushViewController:vc animated:YES];
}

- (void)showCompanySizeChoose
{
    WEAKSELF
    [[LDCheckPublicInfo shareInstance] checkoutCompanySize:^(NSArray<NSDictionary *> * _Nonnull data) {
        
        NSArray *titleArr = [self getArrFormDictArrFilterKey:@"companysize_text" arrDict:data];
        NSArray *titleArrID = [self getArrFormDictArrFilterKey:@"companysize_id" arrDict:data];
        
        [self showLDActionSheetView:nil labHeight:nil labsTitleArr:titleArr selClosure:^(NSInteger index) {
            
            weakSelf.segmentView.eduButton.selected = NO;
            weakSelf.filterId = titleArrID[index];
            weakSelf.filterType = @"size";
            [weakSelf loadUserInfo];
            
            
        }];
        
    }];
}

- (void)editCompanySize {
//    WEAKSELF
//    [weakSelf showCompanySizeChoose];
    UIActionSheet *act = [[UIActionSheet alloc] initWithTitle:@"公司规模" delegate:nil cancelButtonTitle:@"取消" destructiveButtonTitle:nil otherButtonTitles:nil];
    for (DDCompanySize *size in self.sizeArray) {
        [act addButtonWithTitle:size.companysize_text];
    }
    WEAKSELF
    [act bk_setDidDismissBlock:^(UIActionSheet *act, NSInteger idx) {
        if (idx != act.cancelButtonIndex) {
            DDCompanySize *size = weakSelf.sizeArray[idx-1];
            [weakSelf showLoading];
            [weakSelf.service eidtInfoType:DDBossInfoTypeCompanySize value:size.companysize_id callback:^(BOOL succ, NSString *err) {
                if (succ) {
                    [weakSelf hideLoading];
                    [weakSelf loadUserInfo];
                }
                else {
                    [weakSelf showErrorWithText:err];
                }
            }];
        }
    }];
    [act showInView:self.view];

}


- (void)editIntroduce {
    DDTextViewEditViewController *vc = [[DDTextViewEditViewController alloc] initWithMaxCharacterNumber:500];
    vc.title = @"团队介绍";
    vc.value = self.userInfo.teamintro;
    WEAKSELF
    vc.block = ^(NSString *str) {
        [weakSelf showLoading];
        [weakSelf.service eidtInfoType:DDBossInfoTypeIntro
                                 value:str callback:^(BOOL succ, NSString *err)
        {
            if (succ) {
                
                [weakSelf hideLoading];
                [weakSelf loadUserInfo];
            }
            else {
                [weakSelf showErrorWithText:err];
            }
        }];
    };
    [self.navigationController pushViewController:vc animated:YES];
}

- (void)editAvatar {
    WEAKSELF;
    DDAvatarPickerView *avatar = [DDAvatarPickerView instanciate];
    [avatar showWithAnimation:YES];
    avatar.didSelectAvatarType = ^(NSInteger type) {
        if (type == 2) {
            DDDefaultsAvatarView *defaults = [DDDefaultsAvatarView instanciate];
            [defaults showWithAnimation:YES];
            
            defaults.didGetImage = ^(UIImage *img) {
                [weakSelf uploadImage:img];
            };
        }
        else if (type == 0) {
            [[CCImageGetter sharedImageGetter] takePhoto];
            [CCImageGetter sharedImageGetter].callback = ^(UIImage *img) {
                
                
                UIImage *clipimg = [DDUtils handleImage:img withSize:CGSizeMake(640, 640)];
                [weakSelf uploadImage:clipimg];
            };
        }
        else if (type == 1) {
            [[CCImageGetter sharedImageGetter] selectFromAlbum];
            [CCImageGetter sharedImageGetter].callback = ^(UIImage *img) {
                [weakSelf uploadImage:img];
            };
        }
    };
}

- (void)uploadImage:(UIImage *)img {
    WEAKSELF
    [self showLoading];
    [self.service eidtInfoType:DDBossInfoTypeAvatar value:UIImageJPEGRepresentation(img, 0.2) callback:^(BOOL succ, NSString *err) {
        if (succ) {
            [weakSelf hideLoading];
            [weakSelf loadUserInfo];
            
            [[NSNotificationCenter defaultCenter] postNotificationName:NOTI_BOSS_EDIT_PERSIONINFO object:nil];

            [[LDUserInfoNet sharedInstance] queryToken:^(NSString * _Nonnull data) {
                
            } failure:nil];
            
        }
        else {
            [weakSelf showText:@"图片上传失败，请重试"];
        }
    }];
}

//数据校验
- (void)checkData
{

    if (!self.userInfo.logo) {
        
        self.haveLogo = NO;
    }else{
        
        self.haveLogo = YES;
    }
    
    if (!self.userInfo.name) {
        
        self.haveName = NO;
    }else{
        
        self.haveName = YES;
    }
    
    if (!self.userInfo.weixin) {
        
        self.haveWeiXin = NO;
    }else{
        
        self.haveWeiXin = YES;
    }
    
    if (!self.userInfo.positioncustomized && !self.userInfo.positionname) {
        
        self.havePosition = NO;
    }else{
        
        self.havePosition = YES;
    }
    
    if (!self.userInfo.teamhighlightscount || [self.userInfo.teamhighlightscount isEqualToString:@"0"]) {
        
        
        self.haveLight = NO;
    }else{
        
        self.haveLight = YES;
    }
    
    if (!self.userInfo.teamintro) {
        
        self.haveCompanyIntro = NO;
    }else{
        
        self.haveCompanyIntro = YES;
    }
    
    if (!self.userInfo.companyshortname) {
        
        self.haveCompanyShotrName = NO;
    }else{
        
        self.haveCompanyShotrName = YES;
    }
    
    if (!self.userInfo.industry) {
        
        self.haveCompanyStyle = NO;
    }else{
        
        self.haveCompanyStyle = YES;
    }
    
    if (!self.userInfo.companysize) {
        
        self.haveCompanySize = NO;
    }else{
        
        self.haveCompanySize = YES;
    }
    
    if (self.companyInfo.companyshow.count == 0) {
        
        self.haveCompanyShow = NO;
    }else{
        
        self.haveCompanyShow = YES;
    }
    
    
    if (!self.userInfo.companyfullname) {
        
        self.haveCompanyLongName = NO;
    }else{
        
        self.haveCompanyLongName = YES;
    }
    
    
    if (!self.userInfo.companywebsite) {
        
        self.haveCompanyWebsize = NO;
    }else{
        
        self.haveCompanyWebsize = YES;
    }
    
    
    if (!self.userInfo.companyaddress) {
        
        self.haveCompanyAddress = NO;
    }else{
        
        self.haveCompanyAddress = YES;
    }
}


- (void)saveAction
{
    
    [self checkData];
    
    [self.tableView reloadData];
    
    if (self.haveLogo == NO || self.haveName == NO || self.haveWeiXin == NO || self.havePosition == NO ||self.haveLight == NO || self.haveCompanyIntro == NO ||self.haveCompanyShotrName == NO || self.haveCompanyStyle == NO || self.haveCompanySize == NO || self.haveCompanyShow == NO || self.haveCompanyLongName == NO || self.haveCompanyWebsize == NO || self.haveCompanyAddress == NO) {
        
        
        WEAKSELF
        [weakSelf ShowZTCustomTiteAlertViewCancleTitle:@"退出编辑" sureTitle:@"继续编辑" title:@"提示" info:@"信息未填写完整" sure:nil cancel:^{
            
            [self.navigationController popViewControllerAnimated:YES];
        }];
        
    }else{
    
    
        [self.navigationController popViewControllerAnimated:YES];
    }
    
}

- (void)changeStateCellRow:(NSInteger )cellRow CellSection:(NSInteger )cellSection
{

    NSIndexPath *indexPath = [NSIndexPath indexPathForRow:cellRow inSection:cellSection];

    DDEditInfoCell *cell = [self.tableView cellForRowAtIndexPath:indexPath];
    
    cell.titleLabel.textColor = COLOR_FONT_RED;
    
    cell.infoLabel.textColor = COLOR_FONT_RED;
}

-(void)doBack
{
    
    [self saveAction];
}

@end
